% load ../data/DataforMatlab/IP.csv
% load ../data/DataforMatlab/torn.csv

%% Percentile for plotting
% Reshape data
Wfull = reshape(I_vec(:,:,:), [N,T]);
U = reshape(U_vec,[N,T]);
% Initialize variables
PC = zeros(9,T);
Wq = zeros(9,T); 
Uq = zeros(9,T);

for p = 1:9
    PC(p,:) = sum(Wfull <= IP(p,:));
    PC(PC == 0) = 1;
    Wq(p,:) = Wfull(sub2ind(size(Wfull), PC(p,:), 1:T));
    Uq(p,:) = U(sub2ind(size(U), PC(p,:), 1:T));
end

%%Insert NAN into income vectors for which the money metric cannot be calculated.
[~, indmax] = max(U);
[~, indmin] = min(U);
W = NaN(size(Wfull));
Wmax = Wfull(sub2ind(size(Wfull), indmax, 1:T));
Wmin = Wfull(sub2ind(size(Wfull), indmin, 1:T));
for tau = 1:T
    W(indmin(tau):indmax(tau), tau) = Wfull(indmin(tau):indmax(tau), tau);
end

logUmax = max(log(U));
logUmin = min(log(U));


RC = [Wmin;Wq;Wmax]./exp(torn')*52;
OurxaxisUK = [Wmin(:,end);Wq(:,end);Wmax(:,end)]*52;
OuryaxisUK = [exp(logUmin(:,end)+log(52)) ;(Uq(:,end)*52);exp(logUmax(:,end)+log(52)) ];
